#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<assert.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>

void initClient(){
    int tcp_socket_fd = socket(AF_INET,SOCK_STREAM,0);

    struct sockaddr_in server_addr = {0};
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(9999);
    server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");

    int ret = connect(tcp_socket_fd,(struct sockaddr *)&server_addr,sizeof(server_addr));
    printf("connect successful!\n");

    while (1)
    {
        char buf[2048] = {0};
        printf("please input message: ");
        fgets(buf,sizeof(buf),stdin);
        write(tcp_socket_fd,buf,strlen(buf));
        printf("%s",buf);
        printf("%d",strcmp(buf, "exit"));
        if(strcmp(buf, "exit\n") == 0){
            break;
        }
    }

    close(tcp_socket_fd);
    
}

int main(){
    initClient();
    return 0;
}